package top.codecrab.eblog.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author 王刚
 * @since 2023年05月11日 13:31
 */
@Slf4j
@Component
public class RequestUriFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) {
        log.debug("请求路径过滤器初始化");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpRequest = ((HttpServletRequest) servletRequest);
        String requestURI = httpRequest.getRequestURI();
        if (!requestURI.startsWith("/res/") && !requestURI.startsWith("/websocket/") && !requestURI.startsWith("/upload/avatar")) {
            String requestMethod = httpRequest.getMethod();
            log.debug("--------------------- 请求路径：{}, Uri：{} ---------------------", requestMethod, requestURI);
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }

}
